@extends('default.layouts.adminPublic')
@section('title', '资讯发布')

@section('content')
<!--导航开始-->
<div class="crumb_warp">
    <i class="fa fa-home"></i> <a href="{{url('admin')}}">首页</a> &raquo; 资讯管理
</div>
<!--导航结束-->
<!--列表开始-->

    <div class="result_wrap">
        <div class="result_title">
            <h3>资讯列表 <em class="red">{{ session("message") }}</em></h3>
            @include('flash::message')
        </div>
        <!--快捷导航 开始-->
        <div class="result_content">
            <div class="short_wrap">
                <a href="{{ url('admin/news/') }}"><i class="fa fa-mail-reply"></i>资讯管理</a>
                <a href="{{ url('admin/news/create') }}"><i class="fa fa-plus"></i>添加资讯</a>
            </div>
        </div>
        <!--快捷导航 结束-->
    </div>
<form action="{{ url('/admin/news/') }}" method="post" name="newsForm" id="newsForm"  onsubmit="return checkForm('#newsForm')">
    <div class="result_wrap border_buttom">
            {{csrf_field()}}
            <ul class="list_tab make">
                <li class="create-li">
                    <span class="left">文章标题：</span>
                    <span class="right"><input type="text" name="title" value="{{ old('title') }}"></span>
                    <span class="news-err"><em>*{{ $errors->first('title') }}</em><i></i></span>
                </li>
                <li class="create-li">
                    <span class="left">来源：</span>
                    <span class="right"><input type="text" name="source" value="{{ old('source') }}"></span>
                    <span class="news-err"><em>{{ $errors->first('source') }}</em><i>Exp：一网科技</i></span>
                </li>
                <li class="create-li">
                    <span class="left">作者：</span>
                    <span class="right"><input type="text" name="publisher" value="{{ old('publisher') }}"></span>
                    <span class="news-err"><em>{{ $errors->first('publisher') }}</em><i>默认管理员</i></span>
                </li>
                <li class="create-li">
                    <span class="left">所属类别：</span>
                    <span class="right">
                        <select name="firstClass" id="firstClass">
                            @foreach($firstClass as $v)
                                @if(old('firstClass') == $v->id )
                                    <option value="{{ $v->id }}" selected>{{ $v->defectsname }}</option>
                                @else
                                    <option value="{{ $v->id }}">{{ $v->defectsname }}</option>
                                @endif
                             @endforeach
                        </select>
                        <select name="category" id="category">
                            <option><--请先选择左边父类</option>
                        </select>
                    </span>
                    <span class="news-err"><em>{{ $errors->first('category') }}</em><i>选择资讯类别</i></span>
                </li>
                <li class="create-li">
                    <span class="left">标题颜色风格：</span>
                    <span class="right">
                        <select name="style">
                            @foreach($color as $k => $v)
                                @if(old('style') ==  $k )
                                    <option value="{{ $k }}" selected>{{ $v }}</option>
                                @else
                                    <option value="{{ $k }}">{{ $v }}</option>
                                @endif
                            @endforeach

                        </select>
                        </span>
                    <span class="news-err"><em>{{ $errors->first('style') }}</em><i>设置资讯文章标题的颜色</i></span>
                </li>
                <li class="create-li border_buttom">
                    <span class="left">设置推荐：</span>
                    <span class="right">
                        <label for="recommend">推荐</label><input type="radio" id="recommend" name="recommend" value="1"> <label for="noRecommend">取消推荐</label><input type="radio" id="noRecommend" name="recommend" value="0" checked>
                    </span>
                    <span class="news-err"><em>{{ $errors->first('recommend') }}</em><i>设置资讯文章是否为推荐</i></span>
                </li>
            </ul>
            <div class="bbs">
                <div class="title">内容 <em>{{ $errors->first('editorValue') }}</em></div>
            </div>
            <div class="bbs">
                <script id="editor" type="text/plain" style="width:100%;min-height:250px;line-height:20px;">{!! old('editorValue') !!}</script>
            </div>


            <div class="news-submit">
                <div class="submit-left"><input type="hidden" name="img_tag" value="{{ $strRandom or '' }}"></div>
                <div class="submit-right"><input type="button" value="提 交" onclick="document.getElementById('newsForm').submit()"><input type="button" class="back" onclick="history.go(-1)" value="返回"></div>
            </div>
    </div>
</form>
<script>
    var UPLOADER_URL='{{url('/')}}/';
    var uplod_url = "admin/news/upload?img_tag={{ $strRandom }}";
</script>
<script type="text/javascript" charset="utf-8" src="{{asset('/vendor/ueditor/ueditor.config.js')}}"></script>
<script type="text/javascript" charset="utf-8" src="{{asset('/vendor/ueditor/ueditor.all.min.js')}}"> </script>
<script type="text/javascript" charset="utf-8" src="{{asset('/vendor/ueditor/lang/zh-cn/zh-cn.js')}}"></script>
<script type="text/javascript">

   var ue = UE.getEditor('editor');
   ue.ready(function() {
       ue.execCommand('serverparam', '_token', '{{ csrf_token() }}');
       //select 目前只做了2级类
       var jsonObj = {!! $Class !!};
       $("#firstClass").change(function(){
           firstClass = ($("#firstClass").val());
           selectHtml = '';
           for(var item in jsonObj[firstClass]){
               selectHtml += "<option value='"+item+"'>"+jsonObj[firstClass][item]+"</option>";
           }
           $("#category").html(selectHtml);
       });

       //flash session firstClass
       var tempFirstClass = "{{ old('firstClass') }}";
       //defualt select class
       var defaultClass = "{{ $defaultClass or 0 }}";

       selectHtml = '';
       if(tempFirstClass!='' ){
           jsonClass = tempFirstClass;
       }else{
           jsonClass = defaultClass;
       }
       for(var item in jsonObj[jsonClass]){
           selectHtml += "<option value='"+item+"'>"+jsonObj[jsonClass][item]+"</option>";
       }
       $("#category").html(selectHtml);
   });
</script>
@endsection